<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!--  -->
    <script>
        class Son{
            constructor(name,age){
                this.name = name;
                this.age = age;
            }
            // 获取值的时候会触发getter 
            get name(){
                console.log('getter');
            }
            // 改变值会触发setter  拦截
            set name(value){
                console.log(value);
                console.log('setter')
            }

        }
        let tom = new Son('tom',10);
        console.log(tom);
        // 取值会触发getter
        console.log(tom.name);

        // 改变值会触发setter
        tom.name = 'lili';
      
    </script>
</body>
</html>